package com.hyts.rpclet.execute;

import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import net.sf.cglib.reflect.FastMethod;

import java.lang.reflect.InvocationTargetException;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.rpclet.execute
 * author:Libo/Alex
 * create-date:2019-07-09 21:42
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于:
 */
@Builder
public class RpcletMethodInvoker {

    /**
     * rpclet服务对象
     */
    @Getter
    private Object rpcletBean;

    /**
     * fastMethod方法
     */
    @Getter
    private FastMethod fastMethod;

    /**
     * argument type list集合参数类型
     */
    @Getter
    Class<?> argumentTypeList;


    /**
     *
     * @param requestParameter
     * @return
     */
    public Object call(Object requestParameter) {
        try {
            return fastMethod.invoke(rpcletBean, new Object[] { requestParameter });
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}
